package com.zhou.matc

/*
 * @Description: 模式匹配
 * @Author: ZhOu 
 * @Date: 2018/6/13
 */
object MatchDemo {

  //需要注意，匹配的结果和case的先后顺序有关，_相当于default
  def matchTest(x: Any): String = x match {
    case 1 => "One"
    case 2 => "Two"
    case x: Int => "Int"
    case y: String => "String"
    case _ => "未知"
  }

  def main(args: Array[String]): Unit = {
    println(matchTest(1))
    println(matchTest(3))
    println(matchTest("kk"))
    println(matchTest(12.2))
  }
}
